package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.system.domain.vo.SysAssetMaintenanceVo;
import com.ruoyi.system.mapper.SysAssetMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysAssetMaintenanceMapper;
import com.ruoyi.system.domain.SysAssetMaintenance;
import com.ruoyi.system.service.ISysAssetMaintenanceService;
import org.springframework.util.CollectionUtils;

/**
 * 资产维护保养Service业务层处理
 * 
 * @author sxy
 * @date 2025-03-26
 */
@Service
public class SysAssetMaintenanceServiceImpl implements ISysAssetMaintenanceService 
{
    @Autowired
    private SysAssetMaintenanceMapper sysAssetMaintenanceMapper;
    @Autowired
    private SysAssetMapper sysAssetMapper;

    /**
     * 查询资产维护保养
     * 
     * @param maintenanceId 资产维护保养主键
     * @return 资产维护保养
     */
    @Override
    public SysAssetMaintenanceVo selectSysAssetMaintenanceByMaintenanceId(Long maintenanceId)
    {
        SysAssetMaintenance sysAssetMaintenance = sysAssetMaintenanceMapper.selectSysAssetMaintenanceByMaintenanceId(maintenanceId);
        SysAssetMaintenanceVo sysAssetMaintenanceVo = new SysAssetMaintenanceVo();
        BeanUtils.copyProperties(sysAssetMaintenance, sysAssetMaintenanceVo);
        if(sysAssetMaintenance.getAssetId() != null){
            sysAssetMaintenanceVo.setAssetName(sysAssetMapper.selectSysAssetByAssetId(sysAssetMaintenance.getAssetId()).getAssetName());
            sysAssetMaintenanceVo.setAssetNo(sysAssetMapper.selectSysAssetByAssetId(sysAssetMaintenance.getAssetId()).getAssetNo());
        }
        return sysAssetMaintenanceVo;
    }

    /**
     * 查询资产维护保养列表
     * 
     * @param sysAssetMaintenance 资产维护保养
     * @return 资产维护保养
     */
    @Override
    public List<SysAssetMaintenanceVo> selectSysAssetMaintenanceList(SysAssetMaintenance sysAssetMaintenance)
    {
        List<SysAssetMaintenance> sysAssetMaintenances = sysAssetMaintenanceMapper.selectSysAssetMaintenanceList(sysAssetMaintenance);
        List<SysAssetMaintenanceVo> rsp = new ArrayList<>();
        if(!CollectionUtils.isEmpty(sysAssetMaintenances)){
            for (SysAssetMaintenance maintenance : sysAssetMaintenances) {
                SysAssetMaintenanceVo maintenanceVo = new SysAssetMaintenanceVo();
                BeanUtils.copyProperties(maintenance, maintenanceVo);
                //查询资产名称
                if(maintenance.getAssetId() != null){
                    maintenanceVo.setAssetName(sysAssetMapper.selectSysAssetByAssetId(maintenance.getAssetId()).getAssetName());
                    maintenanceVo.setAssetNo(sysAssetMapper.selectSysAssetByAssetId(maintenance.getAssetId()).getAssetNo());
                }
                rsp.add(maintenanceVo);
            }
        }
        return rsp;
    }

    /**
     * 新增资产维护保养
     * 
     * @param sysAssetMaintenance 资产维护保养
     * @return 结果
     */
    @Override
    public int insertSysAssetMaintenance(SysAssetMaintenance sysAssetMaintenance)
    {
        return sysAssetMaintenanceMapper.insertSysAssetMaintenance(sysAssetMaintenance);
    }

    /**
     * 修改资产维护保养
     * 
     * @param sysAssetMaintenance 资产维护保养
     * @return 结果
     */
    @Override
    public int updateSysAssetMaintenance(SysAssetMaintenance sysAssetMaintenance)
    {
        return sysAssetMaintenanceMapper.updateSysAssetMaintenance(sysAssetMaintenance);
    }

    /**
     * 批量删除资产维护保养
     * 
     * @param maintenanceIds 需要删除的资产维护保养主键
     * @return 结果
     */
    @Override
    public int deleteSysAssetMaintenanceByMaintenanceIds(Long[] maintenanceIds)
    {
        return sysAssetMaintenanceMapper.deleteSysAssetMaintenanceByMaintenanceIds(maintenanceIds);
    }

    /**
     * 删除资产维护保养信息
     * 
     * @param maintenanceId 资产维护保养主键
     * @return 结果
     */
    @Override
    public int deleteSysAssetMaintenanceByMaintenanceId(Long maintenanceId)
    {
        return sysAssetMaintenanceMapper.deleteSysAssetMaintenanceByMaintenanceId(maintenanceId);
    }
}
